<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            color:red;
            width: 100px;
            height: 200px;
        }
        .box::after{
            content:"123";
            width:50px;
            height:50px
        }
    </style>
</head>
<body>
    <div class="box">111</div>
    <script>
        // style ：只能操作行间样式（设置，获取）;

        var boxEle = document.querySelector(".box");
        // console.log(boxEle.style.color);
        //1. 获取非行间样式getComputedStyle chrome ie8以上
        // var boxEle = document.querySelector(".box");
        // var res =  getComputedStyle(boxEle)['width'];
        // console.log(res);

    //   var res =   getComputedStyle(boxEle,"after")['width'];
    //   console.log(res);

        // 2.如果是ie8或者以下浏览器 需要使用  currentStyle
        // var res =  boxEle.currentStyle.width;
        // console.log(res);


        // 兼容性的函数；
        function getStyle(ele,styleName){
            if(window.getComputedStyle){
                return getComputedStyle(ele,null)[styleName];
            }else{
               return ele.currentStyle[styleName]
            }
        }
        var res = getStyle(boxEle,"width");
        console.log(res);





    </script>
</body>
</html>